package com.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王霄
 * @date 2022/1/8 17:16
 */
@Configuration
public class FanoutConfig {

    public static final String EXCHANGE_NAME = "fanout.exchange";
    public static final String QUEUE1 = "fanout.queue1";
    public static final String QUEUE2 = "fanout.queue2";

    @Bean(QUEUE1)
    public Queue queue1() {
        return new Queue(QUEUE1);
    }

    @Bean(QUEUE2)
    public Queue queue2() {
        return new Queue(QUEUE2);
    }

    @Bean(EXCHANGE_NAME)
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(EXCHANGE_NAME);
    }

    @Bean
    public Binding fanoutBindingOne() {
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }

    @Bean
    public Binding fanoutBindingTwo() {
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }
}
